using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class PostMenu : BaseItem
    {
        private PostMenu() : base() { }
        private PostMenu(Hashtable table) : base(table) { }
        private PostMenu(Hashtable table, List<PostMenu> collection) : base(table, collection) { }

        private PostMenu(int postId, int menuId, bool included)
            : base() 
        {
            this.postId = postId;
            this.menuId = menuId;
            this.included = included;
        }

        protected override Base CreateDal()
        {
            return new PostMenuDal();
        }
        
        public static PostMenu CreateInstance()
        {
            return new PostMenu();
        }

        public static PostMenu CreateInstance(int postId, int menuId, bool included)
        {
            return new PostMenu(postId, menuId, included);
        }

        private static PostMenu Get(Hashtable table)
        {
            if (table == null)
            {
                return null;
            }
            else
            {
                return new PostMenu(table);
            }
        }

        private static List<PostMenu> Get(Hashtable[] tables)
        {
            if (tables == null)
            {
                return null;
            }
            else
            {
                List<PostMenu> tmp = new List<PostMenu>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new PostMenu(table, tmp));
                }
                return tmp;
            }
        }

        public static List<PostMenu> GetAllByPostId(int postId)
        {
            PostMenuDal dal = new PostMenuDal();
            return Get(dal.GetAllByPostId(postId));
        }


        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((PostMenuDal)dal).Update(postId, menuId, included, ref concurencyId);
        }

        protected override void Load(Hashtable table)
        {
            postId = (int)table[PostMenuDal.Fields.PostId];
            menuId = (int)table[PostMenuDal.Fields.MenuId];
            included = (bool)table[PostMenuDal.Fields.Included];
        }

        private int postId;

        public int PostId
        {
            get { return postId; }
        }

        private int menuId;
        public int MenuId
        {
            get { return menuId; }
        }
        
        private bool included;
        public bool Included
        {
            get { return included; }
            set { included = value; }
        }	
	

    }
}
